/*
游戏每一局输赢动画处理逻辑
*/
cc.Class({
    extends: cc.Component,

    properties: {
        parent:{
            default:null,
            type:cc.Node
        },
        isInit:false,
    },

    onLoad: function () {
    },

    onInit:function(){
        this.winNode = this.node.getChildByName("winNode");
        this.loseNode = this.node.getChildByName("loseNode");
        this.winLight = this.winNode.getChildByName("light");
        this.loseLight = this.loseNode.getChildByName("light");
        this.winImg = this.winNode.getChildByName("mainImg");
        this.loseImg = this.loseNode.getChildByName("mainImg");

        this.isInit = true;
    },

    showAction:function(isWin){
        this.resetNode();
        if(isWin)
        {
            this.winNode.active = true;
            this.winLight.runAction(cc.repeatForever(cc.rotateBy(3,-360)));
            this.winImg.y = 50;
            this.winImg.scale = 1.5;
            this.winImg.runAction(cc.spawn(cc.moveBy(0.3,cc.p(0,-50)),cc.scaleTo(0.3,1)));
        }else{
            this.loseNode.active = true;
            // this.loseLight.runAction(cc.repeatForever(cc.rotateBy(1.5,-360)));
            this.loseImg.y = 50;
            this.loseImg.scale = 1.5;
            this.loseImg.runAction(cc.spawn(cc.moveBy(0.3,cc.p(0,-50)),cc.scaleTo(0.3,1)));
        }

        var self = this;
        var hideAction = function(){
            self.node.runAction(cc.sequence(cc.fadeOut(0.5),cc.callFunc(function () {
                self.node.active = false;
            })));
        };
        this.scheduleOnce(hideAction,2);
    },

    resetNode:function(){
        this.winNode.active = false;
        this.loseNode.active = false;
        this.winLight.stopAllActions();
        this.loseLight.stopAllActions();
        this.winImg.stopAllActions();
        this.loseImg.stopAllActions();
    },

    showLayer:function(isWin){
        if(this.isInit == false)
            this.onInit();
        this.showAction(isWin);
        this.node.active = true;
        this.node.opacity = 255;
    },

    hideLayer:function(){
        this.node.active = false;
    },
});
